package com.zz.framework.core.ext

import android.annotation.SuppressLint
import android.content.Context
import android.text.TextUtils
import android.view.View
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import com.google.android.material.snackbar.Snackbar
import com.zz.framework.core.BaseApp
import com.zz.toast.ToastUtils
import com.zz.toast.style.WhiteToastStyle


fun Context.showToast(content: String) {
    if (content.isNotEmpty()){
        ToastUtils.setStyle(WhiteToastStyle())
        ToastUtils.show(content)
    }
}

@SuppressLint("ResourceType")
fun Context.showToast(@StringRes id: Int) {
    if (id > 0) {
        ToastUtils.setStyle(WhiteToastStyle())
        ToastUtils.show(id)
    }
}

@SuppressLint("ResourceType")
fun Fragment.showToast(@StringRes id: Int) {
    if (id > 0) {
        activity?.let {
            it.showToast(it.getString(id))
        }
    }
}

fun Fragment.showToast(content: String) {
    if (content.isNotEmpty())
        activity?.let {
            it.showToast(content)
        }
}



fun Any.showToast() {
    if (this != null && TextUtils.isEmpty(this.toString()).not())
        BaseApp.context.showToast(toString())
}

inline fun View.snack(message: String, length: Int = Snackbar.LENGTH_LONG, f: Snackbar.() -> Unit) {
    val snack = Snackbar.make(this, message, length)
    snack.f()
    snack.show()
}